<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>绑定或更新支付宝账号</title>
    <link rel="stylesheet"th:href="@{/static/lib/bootstrap/bootstrap.min.css}">
    <script th:src="@{/static/lib/jquery/1.9.1/jquery.js}"></script>
    <script th:src="@{/static/lib/jquery.validation/1.14.0/jquery.validate.js}"></script>
    <script th:src="@{/static/lib/jquery.validation/1.14.0/messages_zh.js}"></script>
    <script th:src="@{/static/lib/vue.min.js}"></script>
    <script type="text/javascript" th:src="@{/static/lib/layer/2.4/layer.js}"></script>
</head>
<body>
<div class="container">

    <form id="editUserForm">
        <div class="form-group" style="display: none">
            <label for="teacherid">教师id：</label>
            <input type="text" class="form-control" id="teacherid" name="username" th:value="${id}" >
        </div>
        <div class="form-group">
            <label for="zhanghao">支付宝账户：</label>
            <input type="text" class="form-control" id="zhanghao" name="zhifubao" th:value="${teacherZhifubao}" required="required">
        </div>
        <div class="form-group">
            <label for="mima">提现密码：</label>
            <input type="text" class="form-control" id="mima" name="pwd" required="required">
        </div>
        <div class="form-group">
            <button type="button" id="saveBtn" class="btn btn-success">确定</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
    </form>
</div>
</body>
<script type="text/javascript">
    /**
     * LYT
     * 绑定或更新支付宝账号
     */
    var bangding=function () {
        $.ajax({
            url:'/addTeacherZhifubao',
            type:'POST',
            dataType:'JSON',
            data:({
                id:$("#teacherid").val(),
                teacherZhifubao:$("#zhanghao").val(),
                teacherTxpwd:$("#mima").val()
            }),
            success:function (result) {
                if(result=="0"){
                    layer.msg('添加失败,请重新添加')
                }else {
                    window.history.back(-1);
                }
            }
        })
    }

    function validform(){
        return $("#editUserForm").validate({
            rules: {
                zhifubao: {
                    minlength:15,
                    maxlength: 15
                },
                pwd: {
                    minlength:6,
                    maxlength: 6
                }
            },
            messages: {
                zhifubao: {
                    minlength:"支付宝账号为15位数",
                    maxlength: "支付宝账号为15位数"
                },
                pwd: {
                    minlength:"提现密码为6位数",
                    maxlength: "提现密码为6位数"
                }
            }
        })
    }
    $(validform());
    $("#saveBtn").click(function () {
        if(validform().form()){
            bangding()
        }
    });
    $("#cancelBtn").click(function () {
        location.href='/toWallet?id='+[[${session.teacher.teacherId}]]
    })
</script>


</html>
